#pragma once

#include <Windows.h>
#include <memory>
#include <thread>
#include <list>

class LogAction;

class SerialSingleton
{
public:
	SerialSingleton(void);
	~SerialSingleton(void);

	static SerialSingleton& getInstance();

	void Register(LogAction* log);
	void Unregister(LogAction* log);

	size_t write(const void* buf, size_t count);

	size_t read(void* buf, size_t count, unsigned int timeout);

	bool open(const char* pathname);

	static void run(SerialSingleton* pThis);

private:
	HANDLE m_hCom;

	std::shared_ptr<std::thread> serial_thread_;

	std::list<LogAction*> register_action_;
};
